package com.kt.uokos.yimo.controller;

import com.kt.uokos.yimo.service.StatService;
import com.kt.uokos.yimo.util.ResponseUtil;
import com.kt.uokos.yimo.vo.StatVo;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @description: TODO
 * @className: StatController.java
 * @author: Kang Hao
 * @date: 2022/4/30 16:52
 **/

@RestController
@RequestMapping("/admin/stat")
@Validated

public class StatController {

    @Resource
    private StatService statService;


    @GetMapping("/user")
    public Object statUser(){
        List<Map> rows = statService.statUser();
        StatVo statVo = new StatVo();
        String[] columns = new String[]{"day", "users"};
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }

    @GetMapping("/order")
    public Object statOrder(){
        List<Map> rows = statService.statOrder();
        String[] columns = new String[]{"day", "orders", "customers", "amount", "pcr"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }

    @GetMapping("/goods")
    public Object statGoods() {
        List<Map> rows = statService.statGoods();
        String[] columns = new String[]{"day", "orders", "products", "amount"};
        StatVo statVo = new StatVo();
        statVo.setColumns(columns);
        statVo.setRows(rows);
        return ResponseUtil.ok(statVo);
    }

}
